<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item size="mini">
        <el-button  type="primary" @click="addOrUpdateHandle()">添加采购单</el-button>
        <el-button  type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;"
      size="mini">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="billNo"
        header-align="center"
        align="center"
        label="采购单据号">
      </el-table-column>
      <el-table-column
        prop="submitName"
        header-align="center"
        align="center"
        label="采购人">
      </el-table-column>
      <el-table-column
        prop="productionLine"
        header-align="center"
        align="center"
        label="产线">
      </el-table-column>
      <el-table-column
        prop="codeAndCount"
        header-align="center"
        align="center"
        label="工夹具代码及其数量">
      </el-table-column>
      <el-table-column
        prop="status"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status === '0'">初审未通过</span>
          <span v-else-if="scope.row.status === '1'">初审通过</span>
          <span v-else-if="scope.row.status === '2'">终审未通过</span>
          <span v-else>终审通过</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="update">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="dataForm.pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="dataForm.pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from "../purchase/purchaseincomesubmitmine-add-or-update"
export default {
  name: "purchaseincomesubmitmine",
  data () {
    return {
      labelPosition:'right',
      minTime:'2021-05-18 12:00:00',//时间戳，对应时间为：'2021-04-20 12:00:00'   1684380304000
      maxTime:1619323200000,//时间戳，对应时间为：'2021-04-25 12:00:00'
      startPickerOptions:{
        disabledDate: (time) => {
          if (this.dataForm.endDate === '') return false;
          //小于最小时间或者大于最大时间都不可选
          var end = new Date(this.dataForm.endDate).getTime();
          return time.getTime() > end;
        }
      },
      endPickerOptions:{
        disabledDate: (time) => {
          if (this.dataForm.startDate === '') return false;
          //小于最小时间或者大于最大时间都不可选
          var start = new Date(this.dataForm.startDate).getTime();
          return time.getTime() < start;
        }
      },
      productionLineOptions:[],
      options: [{
        value: 0,
        label: '初审未通过'
      }, {
        value: 1,
        label: '初审通过'
      }, {
        value: 2,
        label: '终审未通过'
      }, {
        value: 3,
        label: '终审通过'
      }],
      dataForm: {
        key: '',
        code:'',
        pageIndex: 1,
        pageSize: 10,
      },
      dataList: [],
      // pageIndex: 1,
      // pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  computed:{
    // startPickerOptions(){
    //   //选择的日期
    //   let curDate = this.$moment(this.startDate).format("YYYY-MM-DD");
    //   //最小日期
    //   let minDate = this.$moment(this.minTime).format("YYYY-MM-DD");
    //   //前推一天，防止当天日期无法选择
    //   let preTime = this.minTime-24*3600000;
    //   // 如果选择的日期为最小日期，则设置为最小日期的时分秒
    //   let str = "";
    //   if(curDate == minDate){
    //     str = this.$moment(this.minTime).format("HH:mm:ss");
    //   }else{
    //     str = "00:00:00"
    //   }
    //   return {
    //     disabledDate: (time) => {
    //       return time.getTime() < preTime || time.getTime() > this.maxTime;
    //     },
    //     selectableRange: str + " - 23:59:59"
    //   }
    // },
  },
  activated () {
    this.getDataList()
  },
  methods: {
    update(){
      this.$message({
        message: '不要修改啦，球球了~⸝⸝ ᷇࿀ ᷆⸝⸝',
        type: 'success'
      });
    },
    getDataListByLike(){
      this.$http.post(`http://localhost:10000/gongjiajumain/scrapsubmithistory/getformdata`,this.dataForm)
        .then(res=>{
          console.log(this.dataForm)
          console.log("传输成功")
        })
    },
    //清空表格
    clearDataForm(){
      this.dataForm = {}
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      // this.$http({
      //   url: `http://localhost:10000/gongjiajumain/purchaseincomesubmit/list?page=${this.dataForm.pageIndex}&limit=${this.dataForm.pageSize}&key=${this.dataForm.key}`,
      //   method: 'get'
      // }).then(({data}) => {
      //   if (data && data.code === 0) {
      //     this.dataList = data.page.list
      //     this.totalPage = data.page.totalCount
      //   } else {
      //     this.dataList = []
      //     this.totalPage = 0
      //   }
      //   this.dataListLoading = false
      // })
      this.$http.post(`http://localhost:10000/gongjiajumain/purchaseincomesubmit/list1`,this.dataForm)
      .then(data=>{
        if (data.data && data.data.code === 0) {
          this.dataList = data.data.page.list
          this.totalPage = data.data.page.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.dataForm.pageSize = val
      this.dataForm.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.dataForm.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 删除
    deleteHandle (id) {
      var ids = id ? [id] : this.dataListSelections.map(item => {
        return item.id
      })
      this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: "http://localhost:10000/gongjiajumain/scrapsubmithistory/delete",
          method: 'post',
          data: this.$http.adornData(ids, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
